if (typeof CyGem == 'undefined') {
	var CyGem = {
		IsScrollEnabled: true,
		AddLoadEvent: function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function')	{
				window.onload = func;
			} else {
				window.onload = function() {
					if (oldonload) {
						oldonload();
					}
					func();
				};
			}
		},
		AddTouchMoveEvent: function(func) {
			var oldontouchmove = document.ontouchmove;
			if (typeof document.ontouchmove != 'function')	{
				document.ontouchmove = func;
			} else {
				document.ontouchmove = function() {
					if (oldontouchmove) {
						oldontouchmove();
					}
					func();
				};
			}
		},
		Browser: {
			isIE: function() {
				return /MSIE/.test(navigator.userAgent);
			},
			isFF: function() {
				return /Firefox/.test(navigator.userAgent);
			},
			isSafari: function() {
				return /Apple.*Safari/.test(navigator.userAgent);
			},
			isOpera: function() {
				return /Opera/.test(navigator.userAgent);
			},
			isChrome: function() {
				return /Chrome/.test(navigator.userAgent);
			},
			isMobileSafari: function() {
				return /Apple.*Mobile.*Safari/.test(navigator.userAgent);
			},
			isIE6: function() {
				return /MSIE 6/.test(navigator.userAgent);
			},
			isIE7: function() {
				return /MSIE 7/.test(navigator.userAgent);
			},
			isIE8: function() {
				return /MSIE 8/.test(navigator.userAgent);
			},
			isIE9: function() {
				return /MSIE 9/.test(navigator.userAgent);
			},
			isFF2: function() {
				return /Firefox\/2/.test(navigator.userAgent);
			},
			isFF3: function() {
				return /Firefox\/3/.test(navigator.userAgent);
			},
			isIE9Under: function() {
				if (this.isIE() === true && this.isIE9() === false) {
					return true;
				} else {
					return false;
				}
			},
			isAndroidWebkit: function() {
				return /Android.*WebKit/.test(navigator.userAgent);
			}
		},
		Event: {
			fix: function(event) {
				return event || window.event;
			},
			element: function(event) {
				var event = this.fix(event);
				return event.target || event.srcElement;
			},
			pointerX: function(event) {
				var event = this.fix(event);
				if (CyGem.Browser.isMobileSafari())	{
					return event.touches[0].pageX || (event.touches[0].clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
				} else if (CyGem.Browser.isAndroidWebkit()) {
					return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
				} else {
					return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
				}
			},
			pointerY: function(event) {
				var event = this.fix(event);
				if (CyGem.Browser.isMobileSafari())	{
					return event.touches[0].pageY || (event.touches[0].clientY + (document.documentElement.scrollTop || document.body.scrollTop));
				} else if (CyGem.Browser.isAndroidWebkit()) {
					return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
				} else {
					return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
				}
			},
			stop: function(event) {
				var event = this.fix(event);
				if (CyGem.Browser.isIE9Under() == false) {
					event.stopPropagation();
					event.preventDefault();
				} else {
					event.cancelBubble = true;
					event.returnValue = false;
				}
			}
		},
		Element: {
			getHTML: function(element) {
				try {
					var xmlSerializer = new XMLSerializer();
					return  element.nodeType == 4 ? element.nodeValue : xmlSerializer.serializeToString(element);
				} catch(err) {
					if (element.xml || element.outerHTML) {
						return element.xml || element.outerHTML;
					}
					switch (element.childNodes.length) {
						case 0:
							return '';
							break;
						case 1:
							return element.firstChild.nodeValue;
							break;
						default:
							return element.childNodes[1].nodeValue;
							break;
					}
				}
			},
			findAbsPosAndScale: function(element) {
				var curleft = curtop = curWidth = curHeight = 0;
				curWidth = element.offsetWidth;
				curHeight = element.offsetHeight;
				try {
					if (element && element.offsetParent) {
						do {
							if (element.tagName.toLowerCase() == 'body' || element.tagName.toLowerCase() == 'html') {
								break;
							}
							if (element.className == 'sp_rate') {
								curleft += 0;
							} else {
								curleft += element.offsetLeft;
							}
							
							curtop += element.offsetTop;
						} while (element = element.offsetParent);
					}
				} catch(ex) {}
				return {
					left: curleft,
					top: curtop,
					width: curWidth,
					height: curHeight
				};
			},
			checkMouseIsIn: function(x, y, element) {
				var physicalData = this.findAbsPosAndScale(element);
				if (x >= physicalData.left && x <= (physicalData.left + physicalData.width) && y >= physicalData.top && y <= (physicalData.top + physicalData.height)) {
					return true;
				} else {
					return false;
				}
			},
			preventSelectText: function(element) {
				element.onmousedown = function(e) {
					var evt = CyGem.Event.fix(e);
					if (typeof evt.preventDefault != 'undefined') {
						evt.preventDefault();
					}
				};
				element.onselectstart = function() {
					return false;
				};
			},
			addClassName: function(element, className) {
				var classNames = element.className.split(' ');
				var classNamesLength = classNames.length;
				var isClassNameAready = false;
				for (var i = 0; i < classNamesLength; i++) {
					if (classNames[i] == className) {
						isClassNameAready = true;
					}
				}
				if (!isClassNameAready) {
					classNames.push(className);
					element.className = classNames.join(' ');
				}
			}
		}
	};
}

CyGem.StarScoring = {
	units: [],
	Init: function() {
		var divElements = document.getElementsByTagName('div');
		var divElementsLength = divElements.length;
		for (var i = 0; i < divElementsLength; i++) {
			if (divElements[i].className.indexOf('sp_module') >= 0) {
				this.units.push(new this.unit(divElements[i]));
			}
		}
		if (this.IsDragEnabled == true) {
				return true;
			} else {

			}
		if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
			var touchmoveController = function(e) {
				if (CyGem.IsScrollEnabled == false) {
					e.preventDefault();
				}
			};
			CyGem.AddTouchMoveEvent(touchmoveController);
		}
	}
};

CyGem.StarScoring.unit = function(element) {
	this.element = element;
	this.rateElement = null;
	this.tooltipElement = null;
	this.selectElement = null;
	this.touchableStarArea = null;
	this.tootipStarArea = null;
	this.isDragStart = false;
	this.tooltipPointTextNode = null;
	this.bottomPointTextNode = null;
	this.finalPoint = 0;
	this.tempPoint = 0;

	var divElements = this.element.getElementsByTagName('div'),
		divElementsLength = divElements.length;
	for (var i = 0; i < divElementsLength; i++) {
		if (divElements[i].className.indexOf('sp_rate') >= 0 && this.rateElement == null) {
			this.rateElement = divElements[i];
		}

		if (divElements[i].className.indexOf('tooltip') >= 0) {
			this.tooltipElement = divElements[i];
		}
	}
	this.selectElement = this.rateElement.getElementsByTagName('select')[0];
	this.touchableStarArea = this.rateElement.getElementsByTagName('span')[0];
	this.tootipStarArea = this.tooltipElement.getElementsByTagName('span')[0];
	if (this.element.childNodes.length > 3) {
		this.bottomPointTextNode = this.element.childNodes[2];
		this.tooltipPointTextNode = this.tooltipElement.childNodes[2];
	} else {
		this.bottomPointTextNode = this.element.childNodes[1];
		this.tooltipPointTextNode = this.tooltipElement.childNodes[1];
	}
	this.setSelectedPoint(0);

	this.tooltipElement.style.display = 'none';
	CyGem.Element.preventSelectText(this.rateElement);

	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		this.rateElement.ontouchstart = function(obj) {
			var object = obj;
			return function() { object.onDragStart.apply(object, arguments); }; 
		}(this);
		this.rateElement.ontouchmove = function(obj) {
			var object = obj;
			return function() { object.onDraging.apply(object, arguments); }; 
		}(this);
		this.rateElement.ontouchend = function(obj) {
			var object = obj;
			return function() { object.onDragEnd.apply(object, arguments); }; 
		}(this);
	} else {
		this.rateElement.onmouseover = function(obj) {
			var object = obj;
			return function() { object.onDragStart.apply(object, arguments); }; 
		}(this);
		this.rateElement.onmousemove = function(obj) {
			var object = obj;
			return function() { object.onDraging.apply(object, arguments); }; 
		}(this);
		this.rateElement.onclick = function(obj) {
			var object = obj;
			return function() { object.onDragEnd.apply(object, arguments); }; 
		}(this);
		this.rateElement.onmouseout = function(obj) {
			var object = obj;
			return function() { object.onPointerOut.apply(object, arguments); }; 
		}(this);
		this.selectElement.onfocus = function(obj) {
			var object = obj;
			return function() {
				object.rateElement.className = "sp_rate sp_focus";
				object.touchableStarArea.className = 'ico_select';
				object.selectElement.onchange = function() {
					var pt = parseInt(this.options[this.selectedIndex.valueOf()].value, 10) * 10;
					object.setPointByPercentage(pt);
					object.setStarsByPercentage(pt);
				};
			};
		}(this);
		this.selectElement.onblur = function(obj) {
			var object = obj;
			return function() {
				object.rateElement.className = "sp_rate";
				object.touchableStarArea.className = 'ico';
				object.selectElement.onchange = null;
			};
		}(this);
	}
};

CyGem.StarScoring.unit.prototype.onDragStart = function(e) {
	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		CyGem.IsScrollEnabled = false;
	}
	this.isDragStart = true;
	this.showPopup();
	var perValue = this.getPercentage(e);
	this.setClassNameByPoint(perValue);
	this.setStarsByPercentage(perValue);
	this.setPointByPercentage(perValue);
	this.setSelectedPoint(perValue);
};

CyGem.StarScoring.unit.prototype.onDraging = function(e) {
	if (this.isDragStart) {
		var perValue = this.getPercentage(e);
		this.setClassNameByPoint(perValue);
		this.setStarsByPercentage(perValue);
		this.setPointByPercentage(perValue);
		this.setSelectedPoint(perValue);
		this.setClassNameByPoint(perValue);
	}
};

CyGem.StarScoring.unit.prototype.onDragEnd = function(e) {
	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		CyGem.IsScrollEnabled = true;
		this.isDragStart = false;
	}
	var tempStr = this.element.className.split(' ')[1];
	this.finalPoint = parseInt(tempStr.substr(tempStr.indexOf('t') + 1, 2), 10) * 10;
	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		this.setStarsByPercentage(this.finalPoint);
		this.setSelectedPoint(this.finalPoint);
		this.setPointByPercentage(this.finalPoint);
	}
	this.tootipStarArea.removeAttribute('style');
	this.touchableStarArea.removeAttribute('style');
	this.setClassNameByPoint(this.finalPoint);
	this.hidePopup();
};

CyGem.StarScoring.unit.prototype.onPointerOut = function(e) {
	this.isDragStart = false;
	this.setStarsByPercentage(this.finalPoint);
	this.setSelectedPoint(this.finalPoint);
	this.setPointByPercentage(this.finalPoint);
	this.tootipStarArea.removeAttribute('style');
	this.touchableStarArea.removeAttribute('style');
	this.setClassNameByPoint(this.finalPoint);
	this.hidePopup();
}

CyGem.StarScoring.unit.prototype.getPercentage = function(e) {
	var posData = CyGem.Element.findAbsPosAndScale(this.rateElement);
	var percentage =  parseInt(((CyGem.Event.pointerX(e) - posData.left) / posData.width) * 100);
	if (percentage > 100) {
		percentage = 100;
	}
	if (percentage < 0) {
		percentage = 0;
	}
	return percentage;
};

CyGem.StarScoring.unit.prototype.setStarsByPercentage = function(val) {
	this.touchableStarArea.style.width = val + '%';
	this.tootipStarArea.style.width = val + '%';
};

CyGem.StarScoring.unit.prototype.setPointByPercentage = function(val) {
	var point = Math.round(val / 10);
	var pointStr = '' + point;
	if (point < 10) {
		pointStr = '0' + pointStr;
	}
	this.bottomPointTextNode.nodeValue = '(' + pointStr + '점)';
	this.tooltipPointTextNode.nodeValue = '(' + pointStr + '/10)';
};

CyGem.StarScoring.unit.prototype.showPopup = function() {
	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		this.tooltipElement.style.display = 'block';
	}
};

CyGem.StarScoring.unit.prototype.hidePopup = function() {
	if (CyGem.Browser.isMobileSafari() || CyGem.Browser.isAndroidWebkit()) {
		this.tooltipElement.style.display = 'none';
	}
};

CyGem.StarScoring.unit.prototype.setSelectedPoint = function(val) {
	var point = Math.round(val / 10);
	var optionElements = this.selectElement.getElementsByTagName('option');
	optionElements[point].selected = true;
	var optionsLength = optionElements.length;
	for (var i = 0; i < optionsLength; i++) {
		if (i == point) {
			optionElements[i].setAttribute('selected', 'selected');
		} else {
			optionElements[i].removeAttribute('selected');
		}
	}
};

CyGem.StarScoring.unit.prototype.setClassNameByPoint = function(val) {
	var point = Math.round(val / 10);
	if (point >= 10) {
		this.element.className = 'sp_module point10';
	} else {
		this.element.className = 'sp_module point0' + point;
	}
};

// start up
CyGem.AddLoadEvent(function() {CyGem.StarScoring.Init();});